//
//  LDShowHUB.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/5/6.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit
import SVProgressHUD
import WSProgressHUD
import JDStatusBarNotification

class LDShowHUB: NSObject {
    
    var toastStyleDef:ToastStyle?
    
    //入口
    class var shareInstance:LDShowHUB {
        struct Instance {
            static let instance = LDShowHUB()
        }
        return Instance.instance
    }
    //
    func showErr(str:String) {
        
//        let nav = UIApplication.sharedApplication().keyWindow?.rootViewController?.childViewControllers[0]
//        nav?.view.makeToast(str, duration: 1.5, position: .Center, style: toastStyleDef)
    
//        SVProgressHUD.showErrorWithStatus(str)
        NSOperationQueue.mainQueue().addOperationWithBlock {
        WSProgressHUD.showErrorWithStatus(str)
        }
    }
    
    func showSucc(str:String) {
        
//        let nav = UIApplication.sharedApplication().keyWindow?.rootViewController?.childViewControllers[0]
//        nav?.view.makeToast(str, duration: 1.5, position: .Center, style: toastStyleDef)
        
//        SVProgressHUD.showSuccessWithStatus(str)
//        SVProgressHUD.dismiss()
        
        
        NSOperationQueue.mainQueue().addOperationWithBlock {
            
            WSProgressHUD.showSuccessWithStatus(str)
            WSProgressHUD.setProgressHUDIndicatorStyle(WSProgressHUDIndicatorStyle.SmallLight)
            WSProgressHUD.setAnimationCurve(UIViewAnimationCurve.Linear)
            
        }
    }
    
    func showStaus(str:String) {
//        SVProgressHUD.dismiss()
        
//        let nav = UIApplication.sharedApplication().keyWindow?.rootViewController?.childViewControllers[0]
//        nav?.view.make//makeToast(str, duration: 1.5, position: .Center, style: toastStyleDef)
        
//        NSOperationQueue.mainQueue().addOperationWithBlock {
//        
////            WSProgressHUD.showImage(nil, status: str)
////            WSProgressHUD.showImage(nil, status: str, maskType: WSProgressHUDMaskType.Black, maskWithout: .Default)
            WSProgressHUD.showWithStatus(str, maskType: WSProgressHUDMaskType.Black)
//
//            WSProgressHUD.showin
//        }
        
//        SVProgressHUD.showWithStatus(str, maskType: SVProgressHUDMaskType.Black)
    }
    
    func showBarStatus(str:String) {
        
        NSOperationQueue.mainQueue().addOperationWithBlock {
            
            JDStatusBarNotification.showWithStatus(str, styleName: "styleDefault")
            JDStatusBarNotification.dismissAfter(1.5)
        }
        
//        NSTimer.bk_scheduledTimerWithTimeInterval(1.5, block: { (time) in
//            
//            JDStatusBarNotification.dismiss()
//            }, repeats: false)
    }
    
    func dissmiss() {
        SVProgressHUD.dismiss()
        JDStatusBarNotification.dismiss()
        WSProgressHUD.dismiss()
    }
    
    func showToastSucc(str:String) {
        
        NSOperationQueue.mainQueue().addOperationWithBlock {
            
            WSProgressHUD.showImage(nil, status: str)
        }
        
        
    }
    
    func showToastNoti(str:String) {
        
        NSOperationQueue.mainQueue().addOperationWithBlock {
            
             WSProgressHUD.showImage(nil, status: str)
        }
       
    }
    //动态 根据文字适应大小
    func showToastStatus(str:String) {
        
        NSOperationQueue.mainQueue().addOperationWithBlock {
            
            WSProgressHUD.setProgressHUDIndicatorStyle(WSProgressHUDIndicatorStyle.Gray)
            WSProgressHUD.showWithStatus(str, maskType: WSProgressHUDMaskType.Default)
//            WSProgressHUD.showShimmeringString(str)
            
        }
    }
    
    override init() {
        super.init()
        
        //黑色背景
        toastStyleDef = ToastStyle()
        toastStyleDef!.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.2)
        toastStyleDef!.messageFont = LDFont.Font14
        toastStyleDef!.titleFont = LDFont.Font16
        
        ToastManager.shared.queueEnabled = false
        
        JDStatusBarNotification.addStyleNamed("styleDefault") { (barStyle) -> JDStatusBarStyle! in

            let style = JDStatusBarStyle()
            style.barColor = LDGolbalColor.GreenAssist
            style.textColor = LDGolbalColor.White
            style.font = LDFont.Font14
            style.animationType = JDStatusBarAnimationType.Move
            style.progressBarHeight = 15
            
            return style
        }
        
//        SVProgressHUD.setBackgroundLayerColor(UIColor.blackColor().colorWithAlphaComponent(0.3))
//        SVProgressHUD.setForegroundColor(UIColor.blackColor().colorWithAlphaComponent(0.3))
//        SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.Black)
        
        SVProgressHUD.setMinimumDismissTimeInterval(1)
//        SVProgressHUD.setMinimumSize(CGSizeMake(80, 60))
        
        SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.Black)
        
        WSProgressHUD.setProgressHUDIndicatorStyle(WSProgressHUDIndicatorStyle.SmallLight)
        WSProgressHUD.setProgressHUDFont(LDFont.Font14)
    }
}
